class EventBus {
  constructor() {
    this.listener = {}
  }

  on(event, callback) {
    if (!this.listener[event]) {
      this.listener[event] = []
    }
    this.listener[event].push(callback)
  }

  emit(event, detail) {
    if (this.listener[event]) {
      this.listener[event].forEach(callback => {
        callback(detail)
      })
    }
  }

  off(event, callback) {
    if (this.listener[event]) {
      this.listener[event] = this.listener[event].filter(cb => cb !== callback)
    }
  }
}

// 使用示例
const bus = new EventBus();

// 监听事件
bus.on('user:loggedIn', user => {
  console.log('User logged in:', user);
});

// 监听事件
bus.on('user:loggedIn', user => {
  console.log('User 666666666', user);
});

// 触发事件
bus.emit('user:loggedIn', { id: 1, name: 'John Doe' });